package org.jeecg.common.util.wx;

import org.weixin4j.model.pay.PayNotifyResult;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.StringReader;

/**
 * @author guoyh
 * @ClassName WxPayUtil
 * @Description
 * @since 2020/8/29 05:10
 **/
public class WxPayUtil {

    /**
     * 验证签名
     *
     * @param xmlMsg xml参数字符串
     * @return 签名验证，成功返回true,否则返回false
     */
    public static PayNotifyResult xml2Bean(String xmlMsg) {
        try {
            JAXBContext context = JAXBContext.newInstance(PayNotifyResult.class);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            PayNotifyResult result = (PayNotifyResult) unmarshaller.unmarshal(new StringReader(xmlMsg));
            return result;
        } catch (JAXBException ex) {
            return null;
        }
    }
}
